package com.ruoyi.project.system.useinstruct.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.useinstruct.domain.UseInstruct;
import com.ruoyi.project.system.useinstruct.service.IUseInstructService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * app的使用说明Controller
 * 
 * @author ruoyi
 * @date 2021-05-24
 */
@Controller
@RequestMapping("/system/useinstruct")
public class UseInstructController extends BaseController
{
    private String prefix = "system/useinstruct";

    @Autowired
    private IUseInstructService useInstructService;

    @RequiresPermissions("system:useinstruct:view")
    @GetMapping()
    public String useinstruct()
    {
        return prefix + "/useinstruct";
    }

    /**
     * 查询app的使用说明列表
     */
    @RequiresPermissions("system:useinstruct:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UseInstruct useInstruct)
    {
        startPage();
        List<UseInstruct> list = useInstructService.selectUseInstructList(useInstruct);
        return getDataTable(list);
    }

    /**
     * 导出app的使用说明列表
     */
    @RequiresPermissions("system:useinstruct:export")
    @Log(title = "app的使用说明", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UseInstruct useInstruct)
    {
        List<UseInstruct> list = useInstructService.selectUseInstructList(useInstruct);
        ExcelUtil<UseInstruct> util = new ExcelUtil<UseInstruct>(UseInstruct.class);
        return util.exportExcel(list, "app的使用说明数据");
    }

    /**
     * 新增app的使用说明
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存app的使用说明
     */
    @RequiresPermissions("system:useinstruct:add")
    @Log(title = "app的使用说明", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(UseInstruct useInstruct)
    {
        return toAjax(useInstructService.insertUseInstruct(useInstruct));
    }

    /**
     * 修改app的使用说明
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        UseInstruct useInstruct = useInstructService.selectUseInstructById(id);
        mmap.put("useInstruct", useInstruct);
        return prefix + "/edit";
    }

    /**
     * 修改保存app的使用说明
     */
    @RequiresPermissions("system:useinstruct:edit")
    @Log(title = "app的使用说明", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(UseInstruct useInstruct)
    {
        return toAjax(useInstructService.updateUseInstruct(useInstruct));
    }

    /**
     * 删除app的使用说明
     */
    @RequiresPermissions("system:useinstruct:remove")
    @Log(title = "app的使用说明", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(useInstructService.deleteUseInstructByIds(ids));
    }
}
